\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{compat=1.15}

% \usetikzlibrary{}
\usepgfplotslibrary{fillbetween}

\begin{document}


\pgfplotsset{ compat=1.15, }


\begin{tikzpicture}
  \begin{axis}[
		xmin=-5,xmax=5,
		ymin=-0.5,
		ymax=0.5,
		clip=false,
  ]
    \addplot[name path = f,trig format plots=rad] {cos(x)};%
    \addplot[name path = x] {0};

    \addplot fill between[of=f and x,soft clip={domain=-2:4}];
  \end{axis}
\end{tikzpicture}


\end{document}

